<template>
	<view style="padding: 30rpx;">
		<button @click="onSetTimeOut()" type="primary">单次定时器</button>
		<button @click="onSetTimeOut('wym',666)" type="primary" plain="true">启动带参定时器</button>
		<button @click="onClearTimeOut()" type="warn">取消定时器</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: 'wym',
				timer1: null
			}
		},
		methods: {
			onSetTimeOut() {
				console.log("onSetTimeOut()");
				//setTimeOut(callback,ms,args)
				this.timer1 = setTimeOut(() => {
					console.log("onSetTimeOut() callback");
					//...
					console.log("onSetTimeOut() callback end");
				}, 3000);
			},
			// onSetTimeOut(username,pwd){
			// 	console.log("onSetTimeOut()",username,pwd);
			// 	//()=>{ }
			// 	setTimeOut((x,y)=>{
			// 		console.log("--------callback",username,pwd,this.name);
			// 	},2000,username,pwd)
			// },
			onCleartimeOut() {
				console.error("onClearTimeOut() 取消计时器");
				clearTimeOut(this.timer1);
			}
		}
	}
</script>

<style>
	button {
		margin: 20rpx;
	}
</style>